package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bean.acgBeanVo.BaseData;
import com.kuang.demo.bean.lhf.Coupon;
import com.kuang.demo.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String sort, String order,
                           String name, Integer type, Integer status){
        //获取所需数据
        BaseData data = couponService.queryCouponList(page, limit, sort, order,name,type,status);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("read")
    public BaseRespVo read(Integer id) {
        Coupon coupon = couponService.queryCouponRead(id);
        return BaseRespVo.ok(coupon);
    }

    @RequestMapping("listuser")
    public BaseRespVo listuser(Integer id,Integer limit,Integer couponId,
                               String add_time,String order){
        BaseData data = couponService.queryCouponListUser(id,limit,couponId,add_time,order);
        return BaseRespVo.ok();
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Coupon coupon){
        couponService.updateCoupon(coupon);
        return BaseRespVo.ok(coupon);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Coupon coupon){
        couponService.deleteCoupon(coupon);
        return BaseRespVo.ok();
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Coupon coupon){
        Coupon createCoupon = couponService.createCoupon(coupon);
        return BaseRespVo.ok(createCoupon);
    }

}
